package br.univali.compiladores.maquinavirtual;

import java.lang.reflect.InvocationTargetException;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MaquinaVirtual mv = new MaquinaVirtual();
		try {
			for(String arg : args){
				String[] command = arg.split(" ++");
				if(command[1].startsWith("\"")&&  command[1].endsWith("\"")){
					mv.getClass().getDeclaredMethod(command[0].toUpperCase(), String.class).invoke(mv, command[1]);
				} else if(Pattern.matches("^[0-9]{1,10}\\.[0-9]{1,4}$", command[1])){
					mv.getClass().getDeclaredMethod(command[0].toUpperCase(), Float.class).invoke(mv, Float.parseFloat(command[1]));
				} else if(Pattern.matches("^[0-9]{1,10}$", command[1])){
					
					mv.getClass().getDeclaredMethod(command[0].toUpperCase(), Integer.class).invoke(mv, Integer.parseInt(command[1]));
				}
				
			}
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (SecurityException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (InvocationTargetException e) {
			e.printStackTrace();
			System.exit(1);
		}
		System.out.println("Pressione uma tecla para sair");
		Scanner sc = new Scanner(System.in);
		sc.nextByte();
		System.exit(0);
	}

}
